/*
 * Copyright 2013-2015 the original author or authors.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.xdtech.parking.protocol.controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.xdtech.parking.service.ParkingDeviceService;
import com.xdtech.web.model.ResultMessage;

/**
 * 
 * @author max.zheng
 * @create 2015-6-21上午12:24:10
 * @since 1.0
 * @see
 */
@Controller
@Scope("prototype")
public class ParkTestController {
	private Log log = LogFactory.getLog(ParkTestController.class);
	@Autowired
	private ParkingDeviceService parkingDeviceService;
	
	@RequestMapping(value="/parkTest.do",params = "test")
	public ModelAndView test() {
		return new ModelAndView("parking/parkingTest_ftl");
	}
	
	@RequestMapping(value="/parkTest.do",params = "deviceOn")
	@ResponseBody
	public ResultMessage deviceOn(Long id) {
		ResultMessage rs = new ResultMessage();
		if (id!=null) {
			parkingDeviceService.turnOn(id);
		}else {
			rs.setMsg("未选择操作设备");
		}
		
		return rs;
	}
	
	@RequestMapping(value="/parkTest.do",params = "deviceOff")
	@ResponseBody
	public ResultMessage deviceOff(Long id) {
		ResultMessage rs = new ResultMessage();
		if (id!=null) {
			parkingDeviceService.turnOff(id);
		}else {
			rs.setMsg("未选择操作设备");
		}
		
		return rs;
	}
}
